package com.cat.greedyAlgorithm;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves/description/
 * @create 2025/8/22 16:16
 * @since JDK17
 */
public class Solution15 {
    public int minDifference(int[] nums) {
        int n = nums.length, ans;
        if (n <= 4) {
            return 0;
        }
        Arrays.sort(nums);
        ans = Math.min(nums[n - 1] - nums[3], nums[n - 4] - nums[0]);
        ans = Math.min(ans, nums[n - 2] - nums[2]);
        ans = Math.min(ans, nums[n - 3] - nums[1]);
        return ans;
    }
}